//
//  ViewController.m
//  UI
//
//  Created by apple on 2017/7/3.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "ViewController.h"
#import <MWPhotoBrowser.h>
@interface ViewController ()<UIPickerViewDelegate, UIPickerViewDataSource, MWPhotoBrowserDelegate>

@property (nonatomic, strong) NSArray *arr;

@property (nonatomic, copy) NSString *strtr;
@property (nonatomic, copy) NSString *str;

@property (nonatomic, strong) NSMutableArray *mutArr;

@property (nonatomic, strong) NSMutableArray *photos;
@property (nonatomic, strong) NSMutableArray *thumbs;

@property (nonatomic, strong) MWPhotoBrowser *browser;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor colorWithRed:122/255.0 green:123/255.0 blue:34/255.0 alpha:1];
    
    self.mutArrV = [NSMutableArray arrayWithCapacity:0];
    
      NSLog(@"hhjj--%@",_mutArrV);
    
    self.arr = @[@"1", @"2", @"3", @"4", @"5"];
    
    self.str = _arr[0];
    
    NSLog(@"--%@-=",_str);
    
    UIPickerView *pic = [[UIPickerView alloc] initWithFrame:CGRectMake(50, 200, 200, 200)];
    
    pic.delegate = self;
    pic.dataSource = self;
    
    pic.showsSelectionIndicator = YES;
    
//    [self.view addSubview:pic];
//    
//    [self nslogStr];
    
    self.mutArr = [NSMutableArray arrayWithCapacity:0];
    
    [self.mutArr addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3629/3339128908_7aecabc34b.jpg"]]];
    [self.mutArr addObject:[MWPhoto photoWithURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3590/3329114220_5fbc5bc92b.jpg"]]];
    
    NSMutableArray *photos = [[NSMutableArray alloc] init];
    NSMutableArray *thumbs = [[NSMutableArray alloc] init];
    MWPhoto *photo;
//    BOOL displayActionButton = NO;
//    BOOL displaySelectionButtons = NO;
//    BOOL displayNavArrows = NO;
//    BOOL enableGrid = YES;
//    BOOL startOnGrid = NO;
    
    // Photos
//    photo = [MWPhoto photoWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo5" ofType:@"png"]]];
//    photo.caption = @"Fireworks";
//    [photos addObject:photo];
//    photo = [MWPhoto photoWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"photo4" ofType:@"png"]]];
//    photo.caption = @"The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England.";
//    [photos addObject:photo];
//    photo = [MWPhoto photoWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"photo3" ofType:@"png"]]];
//    photo.caption = @"York Floods";
//    [photos addObject:photo];
//    photo = [MWPhoto photoWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo2" ofType:@"png"]]];
//    photo.caption = @"Campervan";
    
    for (int i = 0; i < self.mutArrV.count; i++) {
        
        photo = [MWPhoto photoWithAsset:_mutArrV[i] targetSize:_sizeA];
        
        [photos addObject:photo];
        
        NSLog(@"hh--%@",_mutArrV);
    }
    
//    [photos addObject:photo];
    // Options
    
    
    self.photos = photos;
    self.thumbs = thumbs;
    
    
    //
    // Create browser
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    browser.displayActionButton = YES;//分享按钮,默认是
    browser.displayNavArrows = YES;//左右分页切换,默认否
    browser.displaySelectionButtons = YES;//是否显示选择按钮在图片上,默认否
    browser.alwaysShowControls = YES;//控制条件控件 是否显示,默认否
    browser.zoomPhotosToFill = NO;//是否全屏,默认是
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
    browser.wantsFullScreenLayout = NO;//是否全屏
#endif
    browser.enableGrid = YES;//是否允许用网格查看所有图片,默认是
    browser.startOnGrid = YES;//是否第一张,默认否
    browser.enableSwipeToDismiss = YES;
    [browser showNextPhotoAnimated:YES];
    [browser showPreviousPhotoAnimated:YES];
    [browser setCurrentPhotoIndex:1];
//    browser.photoTitles = @[@"000",@"111",@"222",@"333"];//标题
    
    //    [self presentViewController:browser animated:YES completion:nil];
//    [self.navigationController pushViewController:browser animated:NO];

//    [self addChildViewController:browser];
    //push到MWPhotoBrowser
//    [self presentViewController:browser animated:YES completion:nil];
//    [self.navigationController pushViewController:browser animated:YES];
    
    self.browser = browser;
}

- (void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];
    [self presentViewController:self.browser animated:YES completion:nil];
}

//返回图片个数
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser{
    return _photos.count;
}

//返回图片模型
//- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{
//    
//    //创建图片模型
//    MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3629/3339128908_7aecabc34b.jpg"]];
//    
//    return photo;
//    
//}

//- (id )photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
//    if (index < _photos.count)
//        return [_photos objectAtIndex:index];
//    return nil;
//}

- (id<MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index{
    if (index < _photos.count)
        return [_photos objectAtIndex:index];
    return nil;
    
}


- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{

    UILabel *label = [[UILabel alloc] init];
    
    label.text = _arr[row];
    label.textColor = [UIColor blueColor];
    
    [pickerView.subviews objectAtIndex:1].hidden = YES;
    [pickerView.subviews objectAtIndex:2].hidden = YES;
    
    return label;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{

    return 40;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{

    return 40;
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{

    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

    return _arr.count;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

    NSInteger picRow = [pickerView selectedRowInComponent:0];
        self.str = _arr[picRow];
    
    NSLog(@"--%@--",_str);
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{

    if (!row) {
        
        self.strtr = _arr[0];
    }else{
    
        self.strtr = _arr[row];
    }
    NSLog(@"===%@==",_strtr);
    
    return _strtr;
}

- (void)nslogStr{

    NSLog(@"++%@++",_strtr);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
